package com.gitee.huxing.course.conc.conc03.future;

import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

/**
 * @Description:
 * @ProjectName: JavaCourse
 * @Package: com.gitee.huxing.course.conc.conc03.future
 * @ClassName: FutureTask1
 * @Author: huxingmale
 * @DateTime: 2021-08-25 23:05
 */
public class FutureTask1 {
    public static void main(String[] args) {
        FutureTask<Integer> task = new FutureTask<Integer>(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                return new Random().nextInt();
            }
        });
        new Thread(task).start();
        try {
            System.out.println("result: " + task.get());
        } catch (InterruptedException ex){
            ex.printStackTrace();
        } catch (Exception ex){
            ex.printStackTrace();
        }
    }
}
